home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
238_01
/
mprint.c
< prev
next >
Wrap
Text File
|
1987-07-26
|
20KB
|
715 lines
#include <stdio.h>
#include <ctype.h>
#include <setjmp.h>
#include <stdarg.h>
#include <fcntl.h>
#include <sys\types.h>
#include <io.h>
#include <sys\stat.h>
#define unreadc(ch) ungetc(ch,infile)
#define MAXPARM 9 /* max. number of parameters per function */
#define MAXLPP 88 /* max. number of line per page */
#define TBUFSIZ 16384 /* Text buffer size */
#define Boolean int
#define TRUE 1
#define FALSE 0
#define ERROR (-1)
enum Ptype { /* Parameter Type */
UNDEFINED, INTG, STRG
};
struct funcdesc { /* Function description entry */
char *name; /* name in ASCII */
enum Ptype rettype; /* no return value or expected return type */
int nuparm; /* number of paramters for the functions */
enum Ptype parmstype[MAXPARM]; /* definition parameter type */
};
/* The function names must arrange in ascending order */
/* and same as the order in EXECFUNC.ASM */
struct funcdesc FUNCTIONS[] =
{ { "Arc1", UNDEFINED, 4, { INTG, INTG, INTG, INTG } } ,
{ "Arc2", UNDEFINED, 5, { INTG, INTG, INTG, INTG, INTG } },
{ "ArcPoint", UNDEFINED, 4, { INTG, INTG, INTG, INTG } },
{ "BlockCopy", INTG, 8,
{ INTG, INTG, INTG, INTG, INTG, INTG, INTG, INTG } },
{ "BlockLoad", INTG, 3, { INTG, INTG, STRG } },
{ "BlockSave", UNDEFINED, 5, { INTG, INTG, STRG, INTG, INTG } },
{ "Box", UNDEFINED, 6, { INTG, INTG, INTG, INTG, INTG, INTG } } ,
{ "Circle", UNDEFINED, 3, { INTG, INTG, INTG } } ,
{ "CreateFrame", INTG, 2, { INTG, INTG } } ,
{ "Dot", UNDEFINED, 2, { INTG, INTG } } ,
{ "Draw", UNDEFINED, 3, { STRG, INTG, INTG } },
{ "Earc1", UNDEFINED, 5, { INTG, INTG, INTG, INTG, INTG } } ,
{ "Earc2", UNDEFINED, 6, { INTG, INTG, INTG, INTG, INTG, INTG } },
{ "Ellipse", UNDEFINED, 4, { INTG, INTG, INTG, INTG } } ,
{ "EnvRsto", UNDEFINED, 2, { INTG, INTG } },
{ "EnvSave", INTG, 1, { INTG } },
{ "FillCircle", UNDEFINED, 3, { INTG, INTG, INTG } },
{ "FillEllipse",UNDEFINED, 4, { INTG, INTG, INTG, INTG } },
{ "HorzLine", UNDEFINED, 4, { INTG, INTG, INTG, INTG } } ,
{ "Line", UNDEFINED, 4, { INTG, INTG, INTG, INTG } } ,
{ "LoadFont", INTG, 1, { STRG } } ,
{ "NextXY", UNDEFINED, 2, { INTG, INTG } },
{ "PatternFill", UNDEFINED, 4, { INTG, INTG, STRG, INTG } },
{ "PlotType", INTG, 1, { INTG } } ,
{ "PrintFrame", UNDEFINED, 5, { INTG, STRG, INTG, INTG, INTG } } ,
{ "PrintPage", UNDEFINED, 0 },
{ "ReadStr", UNDEFINED, 7,
{ STRG, INTG, INTG, INTG, INTG, INTG, INTG } },
{ "Rectangle", UNDEFINED, 4, { INTG, INTG, INTG, INTG } } ,
{ "RelOrg", UNDEFINED, 2, { INTG, INTG } } ,
{ "RemvFont", INTG, 1, { INTG } } ,
{ "RemvFrame", INTG, 1, { INTG } } ,
{ "ResetWin", UNDEFINED, 0 } ,
{ "SelectFont", INTG, 1, { INTG } },
{ "SelectFrame", INTG, 1, { INTG } } ,
{ "SetOrg", UNDEFINED, 2, { INTG, INTG } } ,
{ "SetStyle", UNDEFINED, 1, { INTG } } ,
{ "SetWin", UNDEFINED, 4, { INTG, INTG, INTG, INTG } } ,
{ "SolidFill", UNDEFINED, 2, { INTG, INTG } },
{ "VertLine", UNDEFINED, 4, { INTG, INTG, INTG, INTG } },
{ "WriteStr", UNDEFINED, 7, { INTG, INTG, INTG, INTG, STRG, INTG, INTG }},
{ "XHLine", INTG, 5, { INTG, INTG, INTG, INTG, INTG } }
};
/* total number of functions */
#define NFUNC (sizeof(FUNCTIONS) / sizeof(struct funcdesc))
/* Error message in C format string */
char *ERRMSG[]= {
"Undefined Error Number\n",
"Variable/Function name expected\n",
"Variable name %s not found\n",
"Function name or expression expected\n",
"Function name %s not found\n",
"'(' expected after function name\n",
"Type if parameter %d is different from definition\n",
"')' expected after the parameters of a function\n",
"Less parameter than expected\n",
"End of string not detected before end of line\n",
"',' expected after a parameter\n",
"'C' or 'L' expected after '['\n",
"']' expected after a line or column specification\n",
"Idendifier Expected\n"
};
/* total number of error messges */
#define NUOFERROR (sizeof(ERRMSG) / sizeof(char *))
int PATTERN[]={
0x5555, 0xaaaa, 0x5555, 0xaaaa,
0x5555, 0xaaaa, 0x5555, 0xaaaa,
0x5555, 0xaaaa, 0x5555, 0xaaaa,
0x5555, 0xaaaa, 0x5555, 0xaaaa,
0x8888, 0x4444, 0x2222, 0x1111,
0x8888, 0x4444, 0x2222, 0x1111,
0x8888, 0x4444, 0x2222, 0x1111,
0x8888, 0x4444, 0x2222, 0x1111,
0x1111, 0x2222, 0x4444, 0x8888,
0x1111, 0x2222, 0x4444, 0x8888,
0x1111, 0x2222, 0x4444, 0x8888,
0x1111, 0x2222, 0x4444, 0x8888
};
char LINE[160]; /* for variable line */
struct pval { /* parameter record */
enum Ptype parmtype;
union {
int u_int;
char *u_strg;
} v;
};
struct pval RETVAL, *expr();
/* Only first 12 characters of identifier is significant */
/* Maximum number of characters in string(s) per function is 512 */
char IDNAME[12], CHARS[512], *PSPTR;
#define NUOFVAR 21
int nuofvar=NUOFVAR;
char VARNAME[NUOFVAR][12]={
"pattern1", "pattern2", "pattern3",
"line",
"font1", "font2", "font3", "font4",
"frame1", "frame2", "frame3",
"temp1", "temp2", "temp3",
"x1", "x2", "y1", "y2",
"env1", "env2", "env3"
};
struct pval VARTABLE[NUOFVAR];
/* configurable parameters */
int COL_OFFSET=0, ROW_OFFSET=0, LINE_HEIGHT=12, CHAR_WIDTH=12, LINEPERPAGE=66;
int FRAME_WIDTH=960, FRAME_HEIGHT=792, VERT_DEN=0, HORZ_DEN=4;
jmp_buf EOF_JMP, SYNERR_JMP;
int EOF_FLAG=0, TEXT_EOF=0, REMAIN=0;
char TBUF[TBUFSIZ+1], *PAGE[MAXLPP], *PAGEPTR;
FILE *infile; /* GRAD command file */
int textfile; /* text file */
main(argc,argv)
int argc;
char *argv[];
{
char ch;
int ret, frame1;
FILE *fopen();
/* Interpret the options if any */
argv++;
while (argc-- > 1 && *(*argv)++=='-') {
if (**argv) {
ch= *(*argv)++;
ret=atoi(*argv);
} else {
ch=0;
}
switch(ch) {
case 'H':
FRAME_HEIGHT=ret;
break;
case 'W':
FRAME_WIDTH=ret;
break;
case 'c':
COL_OFFSET=ret;
break;
case 'd':
HORZ_DEN=ret & 0x0f;
break;
case 'h':
LINE_HEIGHT=ret;
break;
case 'p':
if (ret > MAXLPP) {
fprintf(stderr,"Max number of line per page is %d\n",MAXLPP);
exit(1);
}
LINEPERPAGE=ret;
break;
case 'r':
ROW_OFFSET=ret;
break;
case 'v':
VERT_DEN=ret ? 0x10 : 0;
break;
case 'w':
CHAR_WIDTH=ret;
break;
default:
fprintf(stderr,"Unknow option -%c ** IGNORED **\n",ch);
break;
}
argv++;
}
/* Any command line argument remain ? */
if ((argc < 1) && (argc > 2)) {
/* no more or too much */
fprintf(stderr,"Usage: mprint [options] commandfile [textfile]\n");
exit(1);
}
(*argv)--;
/* open GRAD command file */
if ((infile=fopen(argv[0], "r")) == (FILE *) NULL) {
fprintf(stderr,"mprint: Command file not found\n");
exit(1);
}
if (argc==2) {
/* Open text file */
if ((textfile=open(argv[1],O_RDONLY | O_BINARY)) == ERROR) {
fprintf(stderr,"mprint: text file not found\n");
exit(1);
}
} else {
TEXT_EOF=TRUE;
}
GRADinit(); /* Initialize GRAD environemnt */
initvars(); /* Initialize my varaibles */
frame1=CreateFrame(FRAME_WIDTH,FRAME_HEIGHT); /* Create Frame */
SelectFrame(frame1); /* use it as default output */
i